#ifndef __IP_PACKET_H__
#define __IP_PACKET_H__ 1

#include <stdint.h>

/* START libnet work-around */
/* _GNU_SOURCE is redefined in libnet.h, the following three lines are
 * suppressed 
 */ 
#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
/* END libnet work-around */

#include <libnet.h>

/* define the following to memcpy(3) the packet buffer */
#undef MEMCPY 

class CIPPacket
{
	public:
		virtual ~CIPPacket();

		static const int sMaxPacketLength;

		static CIPPacket* createIPPacket(uint8_t* pForeignPacketBuffer, int pBufferLength);
		static int destroyIPPacket(CIPPacket* pIPPacket);

		virtual inline int getPacketLength() const { return mBufferLength; }

		virtual bool isUDP() const;
		virtual bool isTCP() const;
		virtual uint32_t getSrcIP() const;
		virtual uint32_t getDstIP() const;
		virtual int getSrcPort() const;
		virtual int getDstPort() const;

    virtual uint8_t* getPayload() const;
		virtual int getPayloadLength() const;
		virtual uint8_t* getPacketBuffer() const;

		virtual void calcChecksum();

	private:
		CIPPacket();
		CIPPacket(uint8_t* pForeignPacketBuffer, int pBufferLength);
		CIPPacket(const CIPPacket& );
		CIPPacket& operator=(const CIPPacket& );

		uint8_t* mPacketBuffer;
		int mBufferLength;

		/* networking stuff */
		struct iphdr* mIP_header;
		struct udphdr* mUDP_header;
		struct tcphdr* mTCP_header;
		uint8_t* mPayload;

		/* helper functions */
};

#endif /* __IP_PACKETH_H__ */

